import React, { useState, useEffect, useCallback } from "react";
import {
  Card,
  Row,
  Col,
  Statistic,
  Progress,
  List,
  Avatar,
  Button,
  Empty,
  Spin,
  notification,
  Space,
  Tag,
  message,
  Badge,
  Tooltip,
  Popconfirm,
  Typography,
  Divider,
  Alert,
} from "antd";
import {
  UserOutlined,
  BookOutlined,
  FormOutlined,
  ClockCircleOutlined,
  TeamOutlined,
  BarChartOutlined,
  FileTextOutlined,
  TrophyOutlined,
  EyeOutlined,
  PlayCircleOutlined,
  CheckCircleOutlined,
  MessageOutlined,
  BellOutlined,
  ReloadOutlined,
  CalendarOutlined,
  StarOutlined,
  FireOutlined,
  RiseOutlined,
  FallOutlined,
  DashboardOutlined,
} from "@ant-design/icons";
import {
  useClasses,
  useDashboardStats,
  useClassMembers,
} from "../../../hooks/useAPI";
import { useUser } from "../../../contexts/UserContext";

interface TeacherStats {
  totalClasses: number;
  totalStudents: number;
  pendingHomework: number;
  averageScore: number;
  completedExams: number;
  activeDiscussions: number;
  thisWeekActivity: number;
  lastWeekActivity: number;
}

interface RecentActivity {
  id: string;
  type:
    | "homework_submitted"
    | "exam_completed"
    | "discussion_created"
    | "student_joined"
    | "resource_uploaded"
    | "grade_updated";
  title: string;
  description: string;
  time: string;
  userName: string;
  userAvatar?: string;
  priority?: "high" | "medium" | "low";
}

interface ClassInfo {
  id: number;
  name: string;
  enrolled: number;
  status: "active" | "ended" | "upcoming";
  progress: number;
  nextClass?: string;
  teacher: string;
  subject: string;
  color: string;
}

const { Text, Title } = Typography;

const TeacherHome: React.FC = () => {
  const { user, isAuthenticated, loading: authLoading } = useUser();
  const [stats, setStats] = useState<TeacherStats>({
    totalClasses: 0,
    totalStudents: 0,
    pendingHomework: 0,
    averageScore: 0,
    completedExams: 0,
    activeDiscussions: 0,
    thisWeekActivity: 0,
    lastWeekActivity: 0,
  });
  const [recentActivities, setRecentActivities] = useState<RecentActivity[]>([]);
  const [mockMessages, setMockMessages] = useState([
    { id: 1, title: "学生李明轩提交了作业《算法分析》", time: "2024-07-01 10:00", unread: true },
    { id: 2, title: "学生王雨涵请假申请已通过", time: "2024-06-30 15:30", unread: false },
    { id: 3, title: "系统：本周有2门课程需批改作业", time: "2024-06-29 18:20", unread: true },
    { id: 4, title: "AI助教：有学生在讨论区提问", time: "2024-06-28 09:10", unread: false },
    { id: 5, title: "学生张浩然完成了期中考试", time: "2024-06-27 14:30", unread: true },
    { id: 6, title: "新学生刘雅琪加入了《数据结构》课程", time: "2024-06-26 11:20", unread: false },
  ]);
  const [mockNotifications, setMockNotifications] = useState([
    { id: 1, title: "系统维护通知", content: "平台将于本周日凌晨2点维护，预计持续2小时。", time: "2024-06-29 12:00", unread: true },
    { id: 2, title: "课程变更提醒", content: "《人工智能》课程时间调整为每周三下午2点。", time: "2024-06-28 16:00", unread: false },
    { id: 3, title: "安全提示", content: "请定期修改密码，建议每3个月更换一次。", time: "2024-06-27 14:20", unread: true },
    { id: 4, title: "新功能上线", content: "AI智能批改功能已上线，欢迎体验使用。", time: "2024-06-26 09:15", unread: false },
    { id: 5, title: "教学资源更新", content: "《机器学习》课程资源包已更新到最新版本。", time: "2024-06-25 16:45", unread: true },
  ]);

  // 丰富的班级数据
  const classes: ClassInfo[] = [
    { 
      id: 1, 
      name: "嵌入式系统开发", 
      enrolled: 25, 
      status: "active", 
      progress: 75,
      nextClass: "今天 14:00",
      teacher: "张教授",
      subject: "计算机科学",
      color: "#1890ff"
    },
    { 
      id: 2, 
      name: "物联网技术", 
      enrolled: 30, 
      status: "active", 
      progress: 60,
      nextClass: "明天 10:00",
      teacher: "李副教授",
      subject: "电子信息",
      color: "#52c41a"
    },
    { 
      id: 3, 
      name: "人工智能基础", 
      enrolled: 35, 
      status: "active", 
      progress: 45,
      nextClass: "后天 16:00",
      teacher: "王教授",
      subject: "人工智能",
      color: "#722ed1"
    },
    { 
      id: 4, 
      name: "数据结构与算法", 
      enrolled: 28, 
      status: "upcoming", 
      progress: 0,
      nextClass: "下周一开始",
      teacher: "陈教授",
      subject: "计算机科学",
      color: "#fa8c16"
    },
  ];

  // 直接设置模拟数据，不调用API
  useEffect(() => {
    if (isAuthenticated && user) {
      console.log("📊 设置模拟数据，避免API调用");

      setStats({
        totalClasses: 4,
        totalStudents: 118,
        pendingHomework: 12,
        averageScore: 87.2,
        completedExams: 8,
        activeDiscussions: 15,
        thisWeekActivity: 156,
        lastWeekActivity: 142,
      });

      setRecentActivities([
        {
          id: "1",
          type: "homework_submitted",
          title: "李明轩提交了《算法分析》作业",
          description: "作业质量优秀，代码结构清晰",
          time: "2小时前",
          userName: "李明轩",
          priority: "high"
        },
        {
          id: "2",
          type: "exam_completed",
          title: "期中考试成绩已发布",
          description: "平均分85.6，优秀率32%",
          time: "4小时前",
          userName: "系统",
          priority: "medium"
        },
        {
          id: "3",
          type: "discussion_created",
          title: "新讨论：机器学习应用案例",
          description: "学生积极参与，已有15条回复",
          time: "6小时前",
          userName: "王雨涵",
          priority: "medium"
        },
        {
          id: "4",
          type: "student_joined",
          title: "新学生加入《数据结构》课程",
          description: "刘雅琪同学已通过审核",
          time: "1天前",
          userName: "刘雅琪",
          priority: "low"
        },
        {
          id: "5",
          type: "resource_uploaded",
          title: "上传了新的教学资源",
          description: "《深度学习实践指南》PDF",
          time: "2天前",
          userName: "王教授",
          priority: "low"
        },
        {
          id: "6",
          type: "grade_updated",
          title: "批量更新了作业成绩",
          description: "《物联网技术》实验报告",
          time: "3天前",
          userName: "系统",
          priority: "medium"
        },
      ]);
    }
  }, [isAuthenticated, user]);

  // 模拟加载状态
  const classesLoading = false;
  const dashboardLoading = false;

  // 获取教师概览数据 - 完全禁用
  const fetchOverviewData = useCallback(async () => {
    console.log("📊 API调用已禁用，使用静态数据");
    // 不执行任何API调用
  }, []);

  // 当用户认证完成后获取数据
  useEffect(() => {
    if (isAuthenticated && !authLoading) {
      fetchOverviewData();
    }
  }, [isAuthenticated, authLoading, fetchOverviewData]);

  // 如果还在认证中，显示加载状态
  if (authLoading) {
    return (
      <div style={{ padding: 24, textAlign: "center" }}>
        <Spin size="large" />
        <p style={{ marginTop: 16 }}>正在验证身份...</p>
      </div>
    );
  }

  // 如果未认证，显示提示
  if (!isAuthenticated) {
    return (
      <div style={{ padding: 24, textAlign: "center" }}>
        <Empty description="请先登录" />
      </div>
    );
  }

  const getActivityIcon = (type: string) => {
    switch (type) {
      case "homework_submitted":
        return <FileTextOutlined style={{ color: "#52c41a" }} />;
      case "exam_completed":
        return <TrophyOutlined style={{ color: "#fa8c16" }} />;
      case "discussion_created":
        return <FormOutlined style={{ color: "#1890ff" }} />;
      case "student_joined":
        return <UserOutlined style={{ color: "#722ed1" }} />;
      case "resource_uploaded":
        return <BookOutlined style={{ color: "#13c2c2" }} />;
      case "grade_updated":
        return <BarChartOutlined style={{ color: "#eb2f96" }} />;
      default:
        return <ClockCircleOutlined style={{ color: "#666" }} />;
    }
  };

  const getActivityTag = (type: string) => {
    switch (type) {
      case "homework_submitted":
        return <Tag color="success">作业</Tag>;
      case "exam_completed":
        return <Tag color="warning">考试</Tag>;
      case "discussion_created":
        return <Tag color="blue">讨论</Tag>;
      case "student_joined":
        return <Tag color="purple">加入</Tag>;
      case "resource_uploaded":
        return <Tag color="cyan">资源</Tag>;
      case "grade_updated":
        return <Tag color="magenta">成绩</Tag>;
      default:
        return <Tag>活动</Tag>;
    }
  };

  const getPriorityColor = (priority?: string) => {
    switch (priority) {
      case "high":
        return "#ff4d4f";
      case "medium":
        return "#faad14";
      case "low":
        return "#52c41a";
      default:
        return "#666";
    }
  };

  const isLoading = classesLoading || dashboardLoading;

  const markMessageRead = (id: number) => setMockMessages(prev => prev.map(msg => msg.id === id ? { ...msg, unread: false } : msg));
  const deleteMessage = (id: number) => setMockMessages(prev => prev.filter(msg => msg.id !== id));
  const refreshMessages = () => setMockMessages([
    { id: 1, title: "学生李明轩提交了作业《算法分析》", time: "2024-07-01 10:00", unread: true },
    { id: 2, title: "学生王雨涵请假申请已通过", time: "2024-06-30 15:30", unread: false },
    { id: 3, title: "系统：本周有2门课程需批改作业", time: "2024-06-29 18:20", unread: true },
    { id: 4, title: "AI助教：有学生在讨论区提问", time: "2024-06-28 09:10", unread: false },
    { id: 5, title: "学生张浩然完成了期中考试", time: "2024-06-27 14:30", unread: true },
    { id: 6, title: "新学生刘雅琪加入了《数据结构》课程", time: "2024-06-26 11:20", unread: false },
  ]);
  const markNotificationRead = (id: number) => setMockNotifications(prev => prev.map(n => n.id === id ? { ...n, unread: false } : n));
  const deleteNotification = (id: number) => setMockNotifications(prev => prev.filter(n => n.id !== id));
  const refreshNotifications = () => setMockNotifications([
    { id: 1, title: "系统维护通知", content: "平台将于本周日凌晨2点维护，预计持续2小时。", time: "2024-06-29 12:00", unread: true },
    { id: 2, title: "课程变更提醒", content: "《人工智能》课程时间调整为每周三下午2点。", time: "2024-06-28 16:00", unread: false },
    { id: 3, title: "安全提示", content: "请定期修改密码，建议每3个月更换一次。", time: "2024-06-27 14:20", unread: true },
    { id: 4, title: "新功能上线", content: "AI智能批改功能已上线，欢迎体验使用。", time: "2024-06-26 09:15", unread: false },
    { id: 5, title: "教学资源更新", content: "《机器学习》课程资源包已更新到最新版本。", time: "2024-06-25 16:45", unread: true },
  ]);

  const activityGrowth = ((stats.thisWeekActivity - stats.lastWeekActivity) / stats.lastWeekActivity * 100).toFixed(1);
  const isActivityGrowing = stats.thisWeekActivity > stats.lastWeekActivity;

  return (
    <div style={{ padding: "24px", background: "#f5f5f5", minHeight: "100vh" }}>
      {/* 欢迎横幅 */}
      <Card 
        style={{ 
          marginBottom: "24px", 
          background: "linear-gradient(135deg, #667eea 0%, #764ba2 100%)",
          border: "none",
          borderRadius: "16px"
        }}
        bodyStyle={{ padding: "32px" }}
      >
        <Row align="middle" justify="space-between">
          <Col>
            <Title level={2} style={{ color: "white", margin: 0 }}>
        👋 欢迎回来，{user?.name || "教师"} 老师！
            </Title>
            <Text style={{ color: "rgba(255,255,255,0.8)", fontSize: "16px" }}>
              今天是美好的一天，让我们开始今天的教学工作吧！
            </Text>
          </Col>
          <Col>
            <Space size="large">
              <Statistic
                title={<Text style={{ color: "rgba(255,255,255,0.8)" }}>本周活动</Text>}
                value={stats.thisWeekActivity}
                valueStyle={{ color: "white", fontSize: "32px" }}
                prefix={<FireOutlined />}
                suffix={
                  <span style={{ fontSize: "14px", color: isActivityGrowing ? "#52c41a" : "#ff4d4f" }}>
                    {isActivityGrowing ? <RiseOutlined /> : <FallOutlined />} {activityGrowth}%
                  </span>
                }
              />
            </Space>
          </Col>
        </Row>
      </Card>

      {/* 统计卡片 */}
      <Row gutter={[16, 16]} style={{ marginBottom: "24px" }}>
        <Col xs={24} sm={12} md={6}>
          <Card hoverable style={{ borderRadius: "12px", border: "none", boxShadow: "0 2px 8px rgba(0,0,0,0.1)" }}>
            <Statistic
              title="管理班级"
              value={stats.totalClasses}
              prefix={<BookOutlined style={{ color: "#1890ff" }} />}
              valueStyle={{ color: "#1890ff", fontSize: "28px" }}
              suffix={<Text type="secondary" style={{ fontSize: "14px" }}>个</Text>}
            />
            <Progress percent={75} showInfo={false} strokeColor="#1890ff" />
          </Card>
        </Col>
        <Col xs={24} sm={12} md={6}>
          <Card hoverable style={{ borderRadius: "12px", border: "none", boxShadow: "0 2px 8px rgba(0,0,0,0.1)" }}>
            <Statistic
              title="学生总数"
              value={stats.totalStudents}
              prefix={<TeamOutlined style={{ color: "#52c41a" }} />}
              valueStyle={{ color: "#52c41a", fontSize: "28px" }}
              suffix={<Text type="secondary" style={{ fontSize: "14px" }}>人</Text>}
            />
            <Progress percent={60} showInfo={false} strokeColor="#52c41a" />
          </Card>
        </Col>
        <Col xs={24} sm={12} md={6}>
          <Card hoverable style={{ borderRadius: "12px", border: "none", boxShadow: "0 2px 8px rgba(0,0,0,0.1)" }}>
            <Statistic
              title="待批作业"
              value={stats.pendingHomework}
              prefix={<FormOutlined style={{ color: "#fa8c16" }} />}
              valueStyle={{ color: "#fa8c16", fontSize: "28px" }}
              suffix={<Text type="secondary" style={{ fontSize: "14px" }}>份</Text>}
            />
            <Progress percent={40} showInfo={false} strokeColor="#fa8c16" />
          </Card>
        </Col>
        <Col xs={24} sm={12} md={6}>
          <Card hoverable style={{ borderRadius: "12px", border: "none", boxShadow: "0 2px 8px rgba(0,0,0,0.1)" }}>
            <Statistic
              title="平均分数"
              value={stats.averageScore}
              precision={1}
              suffix="%"
              prefix={<TrophyOutlined style={{ color: "#722ed1" }} />}
              valueStyle={{ color: "#722ed1", fontSize: "28px" }}
            />
            <Progress percent={87} showInfo={false} strokeColor="#722ed1" />
          </Card>
        </Col>
      </Row>

      {/* 消息和通知 */}
      <Row gutter={[16, 16]} style={{ marginBottom: "24px" }}>
        <Col xs={24} lg={12}>
          <Card 
            title={
              <Space>
                <MessageOutlined style={{ color: "#1890ff" }} />
                <Text strong>最新消息</Text>
                <Tooltip title="刷新">
                  <Button size="small" icon={<ReloadOutlined />} onClick={refreshMessages} />
                </Tooltip>
              </Space>
            } 
            style={{ borderRadius: "12px", border: "none", boxShadow: "0 2px 8px rgba(0,0,0,0.1)" }}
            bodyStyle={{ padding: "16px" }}
          >
            {mockMessages.length === 0 ? (
              <Empty description="暂无消息" image={Empty.PRESENTED_IMAGE_SIMPLE} />
            ) : (
              <List
                dataSource={mockMessages}
                renderItem={item => (
                  <List.Item 
                    actions={[
                      item.unread && (
                        <Button size="small" type="link" onClick={() => markMessageRead(item.id)}>
                          标为已读
                        </Button>
                      ),
                      <Popconfirm title="确定删除该消息？" onConfirm={() => deleteMessage(item.id)} okText="删除" cancelText="取消">
                        <Button size="small" type="link" danger>删除</Button>
                      </Popconfirm>
                    ].filter(Boolean)}
                    style={{ padding: "8px 0" }}
                  >
                    <List.Item.Meta 
                      avatar={
                        <Badge dot={item.unread}>
                          <Avatar icon={<MessageOutlined />} style={{ backgroundColor: item.unread ? "#1890ff" : "#d9d9d9" }} />
                        </Badge>
                      } 
                      title={
                        <span style={{ fontWeight: item.unread ? 600 : 400, color: item.unread ? "#1890ff" : "#333" }}>
                          {item.title}
                        </span>
                      } 
                      description={
                        <span style={{ color: '#999', fontSize: "12px" }}>
                          <ClockCircleOutlined /> {item.time}
                        </span>
                      } 
                    />
                  </List.Item>
                )}
              />
            )}
          </Card>
        </Col>
        <Col xs={24} lg={12}>
          <Card 
            title={
              <Space>
                <BellOutlined style={{ color: "#fa8c16" }} />
                <Text strong>系统通知</Text>
                <Tooltip title="刷新">
                  <Button size="small" icon={<ReloadOutlined />} onClick={refreshNotifications} />
                </Tooltip>
              </Space>
            } 
            style={{ borderRadius: "12px", border: "none", boxShadow: "0 2px 8px rgba(0,0,0,0.1)" }}
            bodyStyle={{ padding: "16px" }}
          >
            {mockNotifications.length === 0 ? (
              <Empty description="暂无通知" image={Empty.PRESENTED_IMAGE_SIMPLE} />
            ) : (
              <List
                dataSource={mockNotifications}
                renderItem={item => (
                  <List.Item 
                    actions={[
                      item.unread && (
                        <Button size="small" type="link" onClick={() => markNotificationRead(item.id)}>
                          标为已读
                        </Button>
                      ),
                      <Popconfirm title="确定删除该通知？" onConfirm={() => deleteNotification(item.id)} okText="删除" cancelText="取消">
                        <Button size="small" type="link" danger>删除</Button>
                      </Popconfirm>
                    ].filter(Boolean)}
                    style={{ padding: "8px 0" }}
                  >
                    <List.Item.Meta 
                      avatar={
                        <Badge dot={item.unread}>
                          <Avatar icon={<BellOutlined />} style={{ backgroundColor: item.unread ? "#fa8c16" : "#d9d9d9" }} />
                        </Badge>
                      } 
                      title={
                        <span style={{ fontWeight: item.unread ? 600 : 400, color: item.unread ? "#fa8c16" : "#333" }}>
                          {item.title}
                        </span>
                      } 
                      description={
                        <div>
                          <div style={{ color: '#666', fontSize: "13px", marginBottom: "4px" }}>{item.content}</div>
                          <span style={{ color: '#999', fontSize: "12px" }}>
                            <ClockCircleOutlined /> {item.time}
                          </span>
                        </div>
                      } 
                    />
                  </List.Item>
                )}
              />
            )}
          </Card>
        </Col>
      </Row>

      {isLoading ? (
        <div style={{ textAlign: "center", padding: "50px" }}>
          <Spin size="large" />
          <p style={{ marginTop: "16px" }}>正在加载数据...</p>
        </div>
      ) : (
        <>
          <Row gutter={[16, 16]}>
            {/* 班级概览 */}
            <Col xs={24} lg={12}>
              <Card
                title={
                  <Space>
                    <BookOutlined style={{ color: "#1890ff" }} />
                    <Text strong>我的班级</Text>
                  </Space>
                }
                extra={
                  <Button
                    type="link"
                    onClick={() => (window.location.href = "/teacher/classes")}
                  >
                    查看全部
                  </Button>
                }
                style={{ borderRadius: "12px", border: "none", boxShadow: "0 2px 8px rgba(0,0,0,0.1)" }}
              >
                {classes && classes.length > 0 ? (
                  <List
                    dataSource={classes.slice(0, 4)}
                    renderItem={(item: ClassInfo) => (
                      <List.Item
                        actions={[
                          <Button
                            type="link"
                            size="small"
                            onClick={() =>
                              (window.location.href = `/teacher/classes/${item.id}`)
                            }
                          >
                            查看详情
                          </Button>,
                        ]}
                        style={{ padding: "12px 0" }}
                      >
                        <List.Item.Meta
                          avatar={
                            <Avatar
                              style={{ backgroundColor: item.color }}
                              icon={<BookOutlined />}
                              size="large"
                            />
                          }
                          title={
                            <div style={{ display: "flex", alignItems: "center", gap: "8px" }}>
                              <Text strong>{item.name}</Text>
                              <Tag color={item.status === "active" ? "green" : item.status === "upcoming" ? "blue" : "red"}>
                                {item.status === "active" ? "进行中" : item.status === "upcoming" ? "即将开始" : "已结束"}
                              </Tag>
                            </div>
                          }
                          description={
                            <div>
                              <Space style={{ marginBottom: "8px" }}>
                              <Tag color="blue">
                                  <TeamOutlined /> {item.enrolled}人
                              </Tag>
                                <Tag color="cyan">
                                  <CalendarOutlined /> {item.nextClass}
                              </Tag>
                            </Space>
                              <div>
                                <Text type="secondary">进度：</Text>
                                <Progress 
                                  percent={item.progress} 
                                  size="small" 
                                  strokeColor={item.color}
                                  showInfo={false}
                                  style={{ width: "100px", display: "inline-block", marginLeft: "8px" }}
                                />
                                <Text type="secondary" style={{ marginLeft: "8px" }}>{item.progress}%</Text>
                              </div>
                            </div>
                          }
                        />
                      </List.Item>
                    )}
                  />
                ) : (
                  <Empty
                    image={Empty.PRESENTED_IMAGE_SIMPLE}
                    description="暂无班级数据"
                  />
                )}
              </Card>
            </Col>

            {/* 最近活动 */}
            <Col xs={24} lg={12}>
              <Card
                title={
                  <Space>
                    <BarChartOutlined style={{ color: "#52c41a" }} />
                    <Text strong>最近活动</Text>
                  </Space>
                }
                extra={<Button type="link">查看全部</Button>}
                style={{ borderRadius: "12px", border: "none", boxShadow: "0 2px 8px rgba(0,0,0,0.1)" }}
              >
                {recentActivities.length > 0 ? (
                  <List
                    dataSource={recentActivities}
                    renderItem={(item) => (
                      <List.Item style={{ padding: "12px 0" }}>
                        <List.Item.Meta
                          avatar={
                            <Avatar
                              icon={getActivityIcon(item.type)}
                              style={{ backgroundColor: "#f5f5f5" }}
                              size="large"
                            />
                          }
                          title={
                            <div style={{ display: "flex", alignItems: "center", gap: "8px" }}>
                              <Text strong>{item.title}</Text>
                              {getActivityTag(item.type)}
                              {item.priority && (
                                <Tag color={getPriorityColor(item.priority)}>
                                  {item.priority === "high" ? "高优先级" : item.priority === "medium" ? "中优先级" : "低优先级"}
                                </Tag>
                              )}
                            </div>
                          }
                          description={
                            <div>
                              <div style={{ color: "#666", marginBottom: "4px" }}>{item.description}</div>
                              <div style={{ fontSize: "12px", color: "#999" }}>
                                <ClockCircleOutlined /> {item.time} • {item.userName}
                              </div>
                            </div>
                          }
                        />
                      </List.Item>
                    )}
                  />
                ) : (
                  <Empty
                    image={Empty.PRESENTED_IMAGE_SIMPLE}
                    description="暂无活动记录"
                  />
                )}
              </Card>
            </Col>
          </Row>

          {/* 快速操作 */}
          <Card 
            title={
              <Space>
                <DashboardOutlined style={{ color: "#722ed1" }} />
                <Text strong>快速操作</Text>
              </Space>
            } 
            style={{ marginTop: "24px", borderRadius: "12px", border: "none", boxShadow: "0 2px 8px rgba(0,0,0,0.1)" }}
          >
            <Row gutter={[16, 16]}>
              <Col xs={24} sm={12} md={6}>
                <Button
                  type="primary"
                  icon={<BookOutlined />}
                  size="large"
                  block
                  onClick={() => (window.location.href = "/teacher/classes/create")}
                  style={{ height: "48px", borderRadius: "8px" }}
                >
                  创建班级
                </Button>
              </Col>
              <Col xs={24} sm={12} md={6}>
                <Button
                  icon={<FileTextOutlined />}
                  size="large"
                  block
                  onClick={() => (window.location.href = "/teacher/resources")}
                  style={{ height: "48px", borderRadius: "8px" }}
                >
                  上传资源
                </Button>
              </Col>
              <Col xs={24} sm={12} md={6}>
                <Button
                  icon={<FormOutlined />}
                  size="large"
                  block
                  onClick={() => (window.location.href = "/teacher/exams/create")}
                  style={{ height: "48px", borderRadius: "8px" }}
                >
                  创建考试
                </Button>
              </Col>
              <Col xs={24} sm={12} md={6}>
                <Button
                  icon={<BarChartOutlined />}
                  size="large"
                  block
                  onClick={() => (window.location.href = "/teacher/analysis")}
                  style={{ height: "48px", borderRadius: "8px" }}
                >
                  学情分析
                </Button>
              </Col>
            </Row>
          </Card>

          {/* 批阅功能 */}
          <Card 
            title={
              <Space>
                <CheckCircleOutlined style={{ color: "#52c41a" }} />
                <Text strong>批阅管理</Text>
              </Space>
            } 
            style={{ marginTop: "24px", borderRadius: "12px", border: "none", boxShadow: "0 2px 8px rgba(0,0,0,0.1)" }}
          >
            <Row gutter={[16, 16]}>
              <Col xs={24} sm={12} md={6}>
                <Button
                  type="primary"
                  icon={<CheckCircleOutlined />}
                  size="large"
                  block
                  onClick={() => (window.location.href = "/teacher/exam-grading")}
                  style={{ height: "48px", borderRadius: "8px", backgroundColor: "#52c41a", borderColor: "#52c41a" }}
                >
                  考试批阅
                </Button>
              </Col>
              <Col xs={24} sm={12} md={6}>
                <Button
                  type="primary"
                  icon={<FileTextOutlined />}
                  size="large"
                  block
                  onClick={() => (window.location.href = "/teacher/homework-grading")}
                  style={{ height: "48px", borderRadius: "8px", backgroundColor: "#fa8c16", borderColor: "#fa8c16" }}
                >
                  作业批改
                </Button>
              </Col>
              <Col xs={24} sm={12} md={6}>
                <Button
                  icon={<TrophyOutlined />}
                  size="large"
                  block
                  onClick={() => (window.location.href = "/teacher/exam-generation")}
                  style={{ height: "48px", borderRadius: "8px" }}
                >
                  智能出题
                </Button>
              </Col>
              <Col xs={24} sm={12} md={6}>
                <Button
                  icon={<MessageOutlined />}
                  size="large"
                  block
                  onClick={() => (window.location.href = "/teacher/discussions")}
                  style={{ height: "48px", borderRadius: "8px" }}
                >
                  讨论管理
                </Button>
              </Col>
            </Row>
          </Card>

          {/* 额外统计信息 */}
          <Row gutter={[16, 16]} style={{ marginTop: "24px" }}>
            <Col xs={24} sm={12} md={8}>
              <Card style={{ borderRadius: "12px", border: "none", boxShadow: "0 2px 8px rgba(0,0,0,0.1)" }}>
                <Statistic
                  title="已完成考试"
                  value={stats.completedExams}
                  prefix={<TrophyOutlined style={{ color: "#fa8c16" }} />}
                  valueStyle={{ color: "#fa8c16" }}
                  suffix="场"
                />
              </Card>
            </Col>
            <Col xs={24} sm={12} md={8}>
              <Card style={{ borderRadius: "12px", border: "none", boxShadow: "0 2px 8px rgba(0,0,0,0.1)" }}>
                <Statistic
                  title="活跃讨论"
                  value={stats.activeDiscussions}
                  prefix={<FormOutlined style={{ color: "#52c41a" }} />}
                  valueStyle={{ color: "#52c41a" }}
                  suffix="个"
                />
              </Card>
            </Col>
            <Col xs={24} sm={12} md={8}>
              <Card style={{ borderRadius: "12px", border: "none", boxShadow: "0 2px 8px rgba(0,0,0,0.1)" }}>
                <Statistic
                  title="本周活动"
                  value={stats.thisWeekActivity}
                  prefix={<FireOutlined style={{ color: "#ff4d4f" }} />}
                  valueStyle={{ color: "#ff4d4f" }}
                  suffix="次"
                />
              </Card>
            </Col>
          </Row>
        </>
      )}
    </div>
  );
};

export default TeacherHome;
